Completed
Pull Request — master (#51)
by Bui Quang
02:21
created

layout.js ➔ Layout   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 52
rs 9.4929
cc 1
nc 1
nop 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A layout.js ➔ ... ➔ this.getRelatedSectionLayout 0 10 1
A layout.js ➔ ... ➔ this.getErrorSingleListingLayout 0 3 1
A layout.js ➔ ... ➔ this.getDefaultSectionLayout 0 10 1
A layout.js ➔ ... ➔ this.getErrorListingWrapperLayout 0 3 1
A layout.js ➔ ... ➔ this.getDeleteButtonLayout 0 3 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var Layout = function() {
2
3
	/**
4
     * Get default section layout.
5
     */
6
    this.getDefaultSectionLayout = function(index) {
7
        return $.ajax({
8
            url: '/wp-admin/admin-ajax.php?action=wpdfi_get_default_layout',
9
            method: 'POST',
10
            data: {
11
                index: index,
12
                include_delete: true
13
            },
14
        })
15
    }
16
17
    /**
18
     * Get related layout of a section, related layout include taxonomies, image upload and image size.
19
     */
20
    this.getRelatedSectionLayout = function(sectionIndex, postType) {
21
        return $.ajax({
22
            url: '/wp-admin/admin-ajax.php?action=wpdfi_get_related_layout',
23
            method: 'POST',
24
            data: {
25
                section_index: sectionIndex,
26
                post_type: postType
27
            },
28
        })
29
    }
30
31
    /**
32
     * Get errors wrapper layout.
33
     */
34
    this.getErrorListingWrapperLayout = function() {
35
        return '<ul class="error-list">%error-list-markup%</ul>';
36
    }
37
38
    /**
39
     * Get single error listing layout.
40
     */
41
    this.getErrorSingleListingLayout = function(errorContent) {
42
        return '<li class="single-error">' + errorContent + '</li>';
43
    }
44
45
    /**
46
     * Get delete button layout.
47
     */
48
    this.getDeleteButtonLayout = function() {
49
        return '<a href="#" class="btn-remove">-</a>';
50
    }
51
52
}
53
54
export default Layout;